import { contextBridge } from 'electron'
import { electronAPI } from '@electron-toolkit/preload'
import axios from 'axios'

const api = {}

if (process.contextIsolated) {
	try {
		contextBridge.exposeInMainWorld('AIOSys', electronAPI)
		contextBridge.exposeInMainWorld('AIOApi', api)
		contextBridge.exposeInMainWorld('axios', createAxios())
	} catch (error) {
		console.error(error)
	}
} else {
	window.electron = electronAPI
	window.api = api
	window.axios = createAxios()
}

function createAxios() {
	return axios.create({
		// 请求的域名
		baseURL: 'https://localhost:7117/api',
		// 超时（5s）
		timeout: 5000,
		// 服务器的返回数据格式
		responseType: 'json',
		headers: {
			'Content-Type': 'application/json;charset=UTF-8'
		}
	})
}
